import { Injectable, OnModuleInit, Logger } from '@nestjs/common';
import { execFile } from 'child_process';
import { RedisService } from '@liaoliaots/nestjs-redis';
import Redis from 'ioredis';

@Injectable()
export class AppService implements OnModuleInit {
  private readonly redis: Redis | null;
  constructor(private readonly redisService: RedisService) {
    this.redis = this.redisService.getOrThrow();
  }
  async onModuleInit() {
    Logger.log(`clear redis config cache success...`);
  }

  private execPromise(shPath) {
    return new Promise((resolve, reject) => {
      execFile(
        shPath,
        { encoding: 'utf8' },
        (error: any, stdout: any, stderr: any) => {
          Logger.log(`stderr: ${stderr}`);
          if (error) {
            reject(error);
            return;
          }
          resolve(stdout.trim());
        },
      );
    });
  }
}
